package com.moshang.mall.auth.controller;

import com.moshang.mall.auth.feign.MemberFeignService;
import com.moshang.mall.auth.vo.UserLoginVo;
import com.moshang.mall.utils.R;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

/**
 * @Author xww
 * @Description //TODO
 * @Date 2020/9/18   11:20
 **/
@Controller
public class LoginController {
    @Resource
    MemberFeignService memberFeignService;

    @RequestMapping("login")
    public String login(UserLoginVo userLoginVo, RedirectAttributes redirectAttributes, HttpSession session){
        R login = memberFeignService.login(userLoginVo);
        if (login.getCode()==0){
            session.setAttribute("loginUser",login.get("data"));
            return "redirect:http://mall.com";
        }else {
            HashMap map=new HashMap();
            map.put("msg",login.get("msg"));
            redirectAttributes.addFlashAttribute("errors",map);
            return "redirect:http://auth.mall.com/login.html";
        }

    }
}
